<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@page import="java.util.List"%>
<%@ page isELIgnored="false" %> <%--isELIgnored=true禁用EL表达式--%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath() %>/layui-v2.6.13/layui/css/layui.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/layui-v2.6.13/layui/layui.js"></script>
<script src="<%=request.getContextPath() %>/js/jquery.min-2.1.1.js"></script>
</head>
<style>
.page-icon {
	width: 1200px;
	margin: 35px auto 0;
	font-size: 0;
	text-align: center;
}

.page-icon button {
	border: none;
	background-color: #efefef;
	padding: 4px 10px 5px;
	font-size: 20px;
}

#currentPage {
	cursor: auto;
	text-align: center;
	width: 40px;
	font-size: 20px;
}
</style>


<body>
	<div style="padding: 20px;">
		<div>
			   <button type="button" class="layui-btn layui-btn-radius layui-btn-primary" onclick="insert()">添加</button>
        </div>

		<div>
			<table class="layui-table">
				<colgroup>

					<col width="50">
					<col width="50">
					<col width="50">
					<col width="50">
					<col width="50">
					<col width="50">
				</colgroup>
				<thead>
					<tr>

						<th>id</th>
						<th>名称</th>
						<th>密码</th>
						<th>权限</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${list}" var="obj">
                    <tr>
                        <td>${obj.id}</td>
                        <td>${obj.mName}</td>
                        <td>${obj.mPass}</td>
                        <td>
                            <c:if test="${obj.mLevel==1}">
                            超级管理员
                            </c:if>
                            <c:if test="${obj.mLevel==0}">
                            管理员
                            </c:if>
                        </td>
                        <td>
                            <c:if test="${obj.mStatus==1}">
                            <span style="color:green;">正常</span>
                            </c:if>
                            <c:if test="${obj.mStatus==0}">
                            <span style="color:crimson;">禁用</span>
                            </c:if>
                        </td>
                        <td>
                            <c:if test="${obj.mLevel==0}">
                                <c:if test="${obj.mStatus==1}">
                                    <button class="layui-btn" onclick="off(${obj.id})">禁用</button>
                                </c:if>
                                <c:if test="${obj.mStatus==0}">
                                    <button class="layui-btn" onclick="on(${obj.id})">启用</button>
                                </c:if>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
			</table>
			<div style="text-align: center;">
                <button onclick="queryByPageNo(1,${totalPage})" class="layui-btn layui-btn-primary">首页</button>
                <button onclick="queryByPageNo(${pageNo-1},${totalPage})" class="layui-btn layui-btn-primary">上一页</button>
                <span>${pageNo} / ${totalPage}页</span>
                <button onclick="queryByPageNo(${pageNo+1},${totalPage})" class="layui-btn layui-btn-primary">下一页</button>
                <button onclick="queryByPageNo(${totalPage},${totalPage})" class="layui-btn layui-btn-primary">尾页</button>
            </div>
		</div>


	</div>
	<script>
	    function insert(){
            layui.use('layer',function(){
                layer.open({
                  type: 2,
                  title: '增加',
                  content: 'addPage',
                  area:['1000px','500px']
                });
            })
        }

    function off(str){
        $.ajax({
            url:"off",
            data:"id="+str,
            type:"POST",
            success:function(obj){
                if(obj=='1'){
                    alert("禁用成功!");
                    location.reload();
                    window.location.reload();
                }else{
                    alert("禁用失败!");
                    location.reload();
                    window.location.reload();
                }
            }
        })

    }
    function on(str){
        $.ajax({
            url:"on",
            data:"id="+str,
            type:"POST",
            success:function(obj){
                if(obj=='1'){
                    alert("启用成功!");
                    location.reload();
                    window.location.reload();
                }else{
                    alert("启用失败!");
                    location.reload();
                    window.location.reload();
                }
            }
        })
    }

     function queryByPageNo(pageNo,totalPage){
        if(pageNo < 1) pageNo=1;
        if(pageNo >totalPage) pageNo -=1;
        window.location.href="list?pageNo="+pageNo;

    }
	</script>
</body>


</html>
